package com.project2.service;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.project2.bean.CommonData;
import com.project2.bean.PageBo;
import com.project2.bean.po.MarketBrand;
import com.project2.bean.po.MarketBrandExample;
import com.project2.bean.vo.DataInWxBrandDetailVo;
import com.project2.bean.vo.DataInWxBrandListVo;
import com.project2.mapper.MarketBrandMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author zhangminghui
 * @date 2022/8/15
 */
@Service
public class WxBrandServiceImpl implements WxBrandService {
    @Autowired
    MarketBrandMapper marketBrandMapper;

    @Override
    public CommonData<DataInWxBrandListVo> queryBrandListInfo(PageBo pageBo) {
        PageHelper.startPage(pageBo.getPage(), pageBo.getLimit());
        MarketBrandExample marketBrandExample = new MarketBrandExample();
        if (pageBo.getSort() != null && pageBo.getOrder() != null) {
            marketBrandExample.setOrderByClause(pageBo.getSort() + " " + pageBo.getOrder());
        }
        // todo：这里传入的sort、order都为null，需要自己手动设计排序
        pageBo.setSort("add_time");
        pageBo.setOrder("desc");
        marketBrandExample.setOrderByClause(pageBo.getSort() + " " + pageBo.getOrder());
        MarketBrandExample.Criteria criteria = marketBrandExample.createCriteria();
        criteria.andDeletedLessThanOrEqualTo(false);
        List<MarketBrand> marketBrands = marketBrandMapper.selectByExample(marketBrandExample);
        PageInfo<MarketBrand> pageInfo = new PageInfo<>(marketBrands);
        return CommonData.data(pageInfo);
    }

    @Override
    public DataInWxBrandDetailVo queryDataInWxBrandDetailVoById(Integer id) {
        DataInWxBrandDetailVo dataInWxBrandDetailVo=marketBrandMapper.queryBrandInfoById(id);
        return dataInWxBrandDetailVo;
    }
}
